from flask import Blueprint, request

from utilsapp.mysql_con import db_delete, db_insert, db_table_pagelist, db_update, db_list

bluePrint = Blueprint('device_repairlog', __name__)
tableName = 'device_repairlog'


# 分页查询
@bluePrint.route('/list', methods=["post"])
def table_list():
    j = db_table_pagelist(tableName, request.json['page'], '', request.json['size'])
    return j


# 设备维修记录
@bluePrint.route('/listByDevice', methods=["post"])
def table_list_bydevice():
    return db_list(f"SELECT * FROM device_repairlog where device_id = {request.json['device_id']}")


# 新增
@bluePrint.route('/add', methods=["post"])
def table_add():
    return db_insert(tableName, request.json)


# 删除
@bluePrint.route('/delete', methods=["post"])
def table_delete():
    id = request.json['id']
    return db_delete(tableName, f'WHERE id=%s', {'id': id})


# 修改
@bluePrint.route('/change', methods=["post"])
def table_change():
    id = request.json['id']
    return db_update(tableName, request.json, f'WHERE id=%s', {'id': id})
